package com.ibiaoke.pay;

import com.github.wxpay.sdk.WXPayConfig;
import com.ibiaoke.common.configs.GlobalConfigs;
import com.ibiaoke.common.configs.GlobalConfigsKey;
import com.ibiaoke.common.exception.ServiceException;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;

/**
 * 微信App支付
 */
public class AppWXPayConfigImpl implements WXPayConfig{
    @Override
    public String getAppID() {
        return GlobalConfigs.getConfigure(GlobalConfigsKey.AppWeChat.app_APP_ID);
    }

    @Override
    public String getMchID() {
        return GlobalConfigs.getConfigure(GlobalConfigsKey.AppWeChat.app_MERCHANT_ID);
    }

    @Override
    public String getKey() {
        return GlobalConfigs.getConfigure(GlobalConfigsKey.AppWeChat.app_API_SECRET);
    }

    @Override
    public InputStream getCertStream() {
        try {
            return new FileInputStream(GlobalConfigs.getConfigure(GlobalConfigsKey.WeChat.CERT_PATH));
        } catch (FileNotFoundException e) {
            throw  new ServiceException("微信支付证书不存在",e);
        }
    }

    @Override
    public int getHttpConnectTimeoutMs() {
        return 3000;
    }

    @Override
    public int getHttpReadTimeoutMs() {
        return 3000;
    }
}
